﻿using System;
using System.Net;

namespace Netbits.Common.General.CommandLine
{
	/// <summary>
	/// Represent an command-line argument with value of IPAddress
	/// </summary>
	public sealed class ArgumentIPAddress : ArgumentBase<IPAddress>
	{
		#region Constructor

		/// <summary>
		/// Create new instance of this class with specified short-name
		/// </summary>
		/// <param name="ShortName_">The short name of this argument</param>
		public ArgumentIPAddress( string ShortName_ ) : base( ShortName_ )
		{
		}

		#endregion

		#region Overrides

		/// <summary>
		/// Parse the specified value to an ip-address type
		/// </summary>
		/// <param name="Value_">Value to parse</param>
		public override void Parse( string Value_ )
		{
			IPAddress ip = IPAddress.None;

			if( !IPAddress.TryParse( Value_, out ip ) )
				throw new Exception( string.Format( "{0} not a valid ip-address", Value_ ) );

			_Value = ip;
			base.IsSet = true;
		}

		#endregion
	}
}
